<?php defined('SYSPATH') or die('No direct script access.');
require ('application/classes/dao/base.php');
class Controller_productskum extends Controller {


	public function action_set(){
		$parm = get($this->request);
        if(!isset($parm['id']) ||($parm['id'])==""){
            die( "id不能为空");
        }
		$data=rpcCall("specification.get",$parm);
		echo View::factory('manager/setProductSku')->bind("data",$data);
	}
	public function action_add(){
		echo '<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />';
		$parm = post($this->request);
		if(!isset($parm['type']) ||($parm['type'])==""){
			die( "type不能为空");
		}
		if(!isset($parm['productId']) ||($parm['productId'])==""){
			die( "productId不能为空");
		}
		if($parm['type'] == 1&&(!isset($parm['id'])||count($parm['id'])==0)&&(!isset($parm['id'])||count($parm['id'])==0)){
			die( "请选择需要配置门店的规格商品");
		}

		if($parm['type'] == 2&&(!isset($parm['sku'])||in_array('', $parm['sku']))){
			die( "设定规格库存不能为空");
		}
		if($parm['type'] ==2){
			$parm['freeze'] = 0;
			rpcCall("productexpresssku.insertbatch",$parm);
			echo "<script>window.location.href='".Url::base()."index.php/productm/detail?id=".$parm['productId']."'</script>";
		}else{

			$parm['list']=rpcCall("productstoresku.getStoreInfoAndStoreSku",$parm);
			echo View::factory('manager/setProductStoresku')->bind("data",$parm);
		}
	}
	public function action_addProductSku(){
		$parm = post($this->request);
		print_r($parm);
		if(!isset($parm['number']) ||count($parm['number'])==0){
			die( "库存数量不能为空");
		}
		if(!isset($parm['storeId']) ||count($parm['storeId'])==0){
			die( "门店不能为空");
		}
		if(!isset($parm['specificationId']) ||($parm['specificationId'])==""){
			die( "规格不能为空");
		}
		if(!isset($parm['productId']) ||($parm['productId'])==""){
			die( "productId不能为空");
		}
		$parm['freeze'] = 0;
		rpcCall("productstoresku.insertbatch",$parm);

		echo "<script>window.location.href='".Url::base()."index.php/productm/detail?id=".$parm['productId']."'</script>";
	}
}